<template>
  <div class="hello">
    <div class="layer1"></div>
    <div class="layer2"></div>
    <div class="layer3"></div>
    <div class="layer4"></div>
    <div class="layer5"></div>
    <div class="title">{{ title }}</div>
  </div>
</template>

<script>
export default {
  name: 'SassStar',
  data() {
    return {
      title: 'Sass星 空',
    }
  }
}
</script>

<style scoped lang="scss">
@function getShadows($n) {
  $shadows: '#{random(200)}vw #{random(200)}vh #fff';
  @for $i from 2 through $n {
    $shadows: '#{$shadows}, #{random(200)}vw #{random(200)}vh #fff';
  }
  @return unquote($shadows);
}

@keyframes moveUp {
  0% {
    transform: translateY(100vh);
  }
  100% {
    transform: translateY(-100vh);
  }
}

$duration: 100s;
$count: 600;

@for $i from 1 through 5 {
  .layer#{$i} {
    $size: #{$i / 2}px;
    $duration: floor($duration / $i);
    $count: $count / 2;
    position: fixed;
    width: $size;
    height: $size;
    border-radius: 50%;
    top: 0;
    left: 0;
    box-shadow: getShadows($count);
    animation: moveUp $duration linear infinite;

    // 使用两个伪元素实现更平滑的衔接
    &:before,
    &:after {
      content: '';
      position: fixed;
      left: 0;
      width: inherit;
      height: inherit;
      box-shadow: inherit;
      border-radius: inherit;
    }

    &:before {
      top: -100vh;
    }

    &:after {
      top: 100vh;
    }
  }
}

.hello {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  .title {
    margin-top: 2.5%;
    font-size: 30px;
    color: rgba(255, 255, 255, 0.5);
    position: relative;
    z-index: 10;
  }
}
</style>
